package com.hue.concurrent.day03;

/*
    wait和notify、notifyAll的使用：
        只有当前线程获取了对象锁后才能调用这三个方法
 */
public class Demo01 {
    private static final Object lock = new Object();

    public static void main(String[] args) {
        new Thread(()->{
            System.out.println("t1执行");
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t1执行其他代码");
        }).start();
        new Thread(()->{
            System.out.println("t2执行");
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t2执行其他代码");
        }).start();

        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        synchronized (lock){
            lock.notify();
//            lock.notifyAll();
        }
    }
}
